#use "matrix.ml";;

let matrix_add_float = matrix_each  Float.add

let matrix_sub_float = matrix_each Float.sub

let matrix_neg_float = matrix_map Float.neg

let matrix_trans_float = trans 0.

let matrix_mult_float = matrix_mul 0. ( +. ) ( *.)  

(** matrix_add test **)
let a = [[1.;2.;3.];[4.;5.;6.];[7.;8.;9.]] ;;
let b = [[1.;0.;0.];[0.;1.;0.];[0.;0.;1.]] ;;
  matrix_add_float 3 3 a b;;

(** matrix_sub test **)
  matrix_sub_float 3 3 a b;;

(** matrix_opp test **)
  matrix_neg_float 3 3 a ;;

(** matrix_trans test **)
  matrix_trans_float 3 3 a ;;

(** matrix_mult test **)
  matrix_mult_float 3 3 3 a b;;

(** 2x2 block matrix **)
let block_matrix_add_float = mmatrix_each 2 2( +. );;

let block_matrix_sub_float = mmatrix_each 2 2 ( -. );;

let block_matrix_neg_float = mmatrix_map 2 2 Float.neg;;

let block_matrix_trans_float = mmtrans 0. 2 2 ;;

let block_matrix_mult_float = mmatrix_mul 0. ( +. ) ( *. ) 2 2 2;;

let block_matrix_to_matrix_float = mM_to_M;;

(** block_matrix_add_float test *)
let a =[[[[1.;1.]; [0.;0.]];
	 [[1.;0.]; [1.;0.]]];
	[[[0.;1.]; [0.;0.]];
	 [[0.;0.]; [1.;1.]]]];;

let b =[[[[0.;0.]; [1.;0.]];
	 [[1.;0.]; [0.;0.]]];
	[[[0.;0.]; [1.;0.]];
	 [[0.;1.]; [0.;0.]]]] ;;

block_matrix_add_float 2 2 a b ;;

block_matrix_sub_float 2 2 a b ;;

block_matrix_neg_float 2 2 a ;;

block_matrix_trans_float 2 2 a ;;

block_matrix_mult_float 2 2 2 a b ;;

let c = block_matrix_to_matrix_float 2 2 2 2 a;;

let d = block_matrix_to_matrix_float 2 2 2 2 b;;

block_matrix_to_matrix_float 
  2 2 2 2(block_matrix_mult_float 2 2 2 a b)  = matrix_mult_float 4 4 4 c d;;
